package BasicKnowledge.BigDecimalTest;


import java.math.BigDecimal;
import java.text.NumberFormat;

/**
 * @time: 2022/1/10/010 11:59
 * @author: Zhurunhe
 * @Version：1
 */
public class BigDecimalDemo {
    public static String getTasksCountRate(int param1, int param2) {
        double value = (double) param1 / (double) param2;
        NumberFormat fmt = NumberFormat.getNumberInstance();
        fmt.setMaximumFractionDigits(2);
        return fmt.format(value);
    }

    public static void main(String[] args) {

//        System.out.println(getTasksCountRate(10,11));
//        System.out.println(getDays("2020-01-01","2020-01-11"));
       /* BigDecimal b1=new BigDecimal("276480.0000");
        BigDecimal b2=new BigDecimal("200000.0000");
        BigDecimal b3=new BigDecimal("276480.0000");
        BigDecimal b4=new BigDecimal("272220.0000");
        BigDecimal b5=new BigDecimal("1");
        BigDecimal b6=new BigDecimal("3");*/

        //加减乘除
//        System.out.println(b1.add(b2));
//        System.out.println(b3.subtract(b4));
//        System.out.println(b5.multiply(b6));

        //除法中，最好能传入需保留几位小数和舍入模式，
        // 1÷3  结果为无限小数的情况下会报错
        //即为 （BigDecimal divisor 除数， int scale 精确小数位，  int roundingMode 舍入模式）
//        System.out.println(b5.divide(b6,3,BigDecimal.ROUND_HALF_UP));

        int fushu = 11 - 22;
//        System.out.println(fushu);


        //保留n位小数且四舍五入
//        System.out.println(b1.setScale(6,BigDecimal.ROUND_HALF_UP));
//        System.out.println(b1);
//        System.out.println(NumericConversion(b1));
//        double d1=48231574.519999995;
//        System.out.println(new BigDecimal(d1+""));
//            BigDecimal.valueOf();
    }


    public static BigDecimal NumericConversion(BigDecimal value) {
        return (value.divide(new BigDecimal("10000"))).setScale(6, BigDecimal.ROUND_HALF_UP);

    }

}
